﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Taste.Internal
{
    internal class TriggerEffectCollection<TTrigger>
        where TTrigger : struct
    {
        private Dictionary<TTrigger, TriggerEffect> _effects = new Dictionary<TTrigger, TriggerEffect>();

        public bool? CanFire(TTrigger triggerName, object parameter)
        {
            TriggerEffect effect;
            if(_effects.TryGetValue(triggerName, out effect))
                return effect.CanFire(parameter);
            else
                return null;
        }

        public bool Fire(TTrigger triggerName, object parameter)
        {
            TriggerEffect effect;
            if(_effects.TryGetValue(triggerName, out effect))
            {
                effect.Fire(parameter);
                return true;
            }
            else
            {
                return false;
            }
        }

        public void SetEffect(TTrigger triggerName, Action effect, Func<bool> condition)
        {
            TriggerEffect triggerEffect = new TriggerEffect();
            triggerEffect.SetEffect(effect, condition);
            _effects[triggerName] = triggerEffect;
        }

        public void SetEffect<TParam>(TTrigger triggerName, Action<TParam> effect, Func<TParam, bool> condition)
        {
            TriggerEffect triggerEffect = new TriggerEffect();
            triggerEffect.SetEffect(effect, condition);
            _effects[triggerName] = triggerEffect;
        }
    }
}
